package tp1;

import java.io.File;
import java.io.FilenameFilter;

public class FilterList {

	public void listeContenu(File dir, final String ext) {
		File[] files = dir.listFiles();
		for (File f : files) {
			if (f.isDirectory()) {
				// System.out.println("Dossier: " + f.getName());
				listeContenu(f, ext);
				File[] f0;
				f0 = f.listFiles(new FilenameFilter() {
					private String ext1 = ext;

					@Override
					public boolean accept(File dir, String name) {
						// TODO Auto-generated method stub
						return name.toLowerCase().endsWith(ext1);
					}
				});
				for(File f1 : f0)
				{
					System.out.println(f1.getName());
				}
				
			} 
			else {
				File[] f2;
				f2 = f.listFiles(new FilenameFilter() {
					private final String ext2 = ext;

					@Override
					public boolean accept(File dir, String name) {
						// TODO Auto-generated method stub
						return name.toLowerCase().endsWith(ext2);
					}
				});
//				for(File f3 : f2)
//				{
//					System.out.println(f3.getName());
//				}
			}

		}
	}

	public static void main(String[] args) {
		File f = new File("/Users/yu-chen/Downloads");
		FilterList lf = new FilterList();
		lf.listeContenu(f, "pdf");
	}
}